//
//  ViewController.m
//  UIPopoverController练习
//
//  Created by chao on 15/2/27.
//  Copyright (c) 2015年 chao. All rights reserved.
//

#import "CZViewController.h"
#import "CZOneViewController.h"
#import "CZMenuTableViewController.h"
#import "CZColorPickerViewController.h"
#import "CZNavgationController.h"

@interface CZViewController ()<CZColorPickerViewControllerDelegate>

@property (nonatomic, strong) UIPopoverController *menuPopover;
@property (nonatomic, strong) UIPopoverController *titlePopover;
@property (nonatomic, strong) UIPopoverController *ColorPopover;
@property (nonatomic, weak) UIButton *seleBtn;
- (IBAction)selectedColorClick:(UIButton *)sender;

- (IBAction)menuClick:(UIBarButtonItem *)sender;
@end

@implementation CZViewController
- (UIPopoverController *)ColorPopover {
    if (_ColorPopover == nil) {
        CZColorPickerViewController *colorPickerVc = [[CZColorPickerViewController alloc] init];
        colorPickerVc.delegate = self;
//        colorPickerVc.selectedColor = ^(UIColor *color) {
//            _seleBtn.backgroundColor = color;
//        };
        _ColorPopover = [[UIPopoverController alloc] initWithContentViewController:colorPickerVc];
        
    }
    return _ColorPopover;
}
- (UIPopoverController *)menuPopover {
    if (_menuPopover == nil) {
//        CZOneViewController *oneVc = [[CZOneViewController alloc] initWithNibName:@"CZOneViewController" bundle:nil];
        
        CZOneViewController *oneVc = [[CZOneViewController alloc] init];
        CZNavgationController *nav = [[CZNavgationController alloc] initWithRootViewController:oneVc];
        _menuPopover = [[UIPopoverController alloc] initWithContentViewController:nav];

    }
    return _menuPopover;
}

- (UIPopoverController *)titlePopover {
    if (_titlePopover == nil) {
        CZMenuTableViewController *menuVc = [[CZMenuTableViewController alloc] init];
        _titlePopover = [[UIPopoverController alloc] initWithContentViewController:menuVc];
    }
    return _titlePopover;
}
/**
 *  点击菜单
 */
- (IBAction)selectedColorClick:(UIButton *)sender {
    _seleBtn = sender;
    [self.ColorPopover presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

- (IBAction)menuClick:(UIBarButtonItem *)sender {
    [self.menuPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  
}

- (IBAction)titleClick:(UIButton *)sender {
    [self.titlePopover presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

- (void)ColorPickerViewController:(UIViewController *)colorPickerVc didSelectedColor:(UIColor *)SeletedColor {
    [_seleBtn setBackgroundColor:SeletedColor];
}

@end
